# This code is part of MaNGOS. Contributor & Copyright details are in AUTHORS/THANKS.
#
# ***** BEGIN GPL LICENSE BLOCK *****
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# ***** END GPL LICENSE BLOCK *****
#
# World of Warcraft, and all World of Warcraft or Warcraft art, images,
# and lore are copyrighted by Blizzard Entertainment, Inc.

set(LIBRARY_NAME shared)

file(GLOB_RECURSE SRC_GRP_AUTH Auth/*.cpp Auth/*.h)
source_group("Auth" FILES ${SRC_GRP_AUTH})

file(GLOB_RECURSE SRC_GRP_COMMON Common/*.cpp Common/*.h)
source_group("Common" FILES ${SRC_GRP_COMMON})

file(GLOB_RECURSE SRC_GRP_CONFIG Config/*.cpp Config/*.h)
source_group("Config" FILES ${SRC_GRP_CONFIG})

file(GLOB_RECURSE SRC_GRP_DATABASE Database/*.cpp Database/*.h)
source_group("Database" FILES ${SRC_GRP_DATABASE})

file(GLOB_RECURSE SRC_GRP_DATASTORE DataStores/*.cpp DataStores/*.h)
source_group("DataStores" FILES ${SRC_GRP_DATASTORE})

file(GLOB_RECURSE SRC_GRP_LOCKQ LockedQueue/*.cpp LockedQueue/*.h)
source_group("LockedQueue" FILES ${SRC_GRP_LOCKQ})

file(GLOB_RECURSE SRC_GRP_LOG Log/*.cpp Log/*.h)
source_group("Log" FILES ${SRC_GRP_LOG})

file(GLOB_RECURSE SRC_GRP_THREAD Threading/*.cpp Threading/*.h)
source_group("Threading" FILES ${SRC_GRP_THREAD})

file(GLOB_RECURSE SRC_GRP_UTIL Utilities/*.cpp Utilities/*.h)
source_group("Utilities" FILES ${SRC_GRP_UTIL})

# Windows specific files
file(GLOB_RECURSE SRC_GRP_WIN Win/*.cpp Win/*.h)

# Linux specific files
file(GLOB_RECURSE SRC_GRP_LINUX Linux/*.cpp Linux/*.h)

set(LIBRARY_SRCS
    ${SRC_GRP_AUTH}
    ${SRC_GRP_CONFIG}
    ${SRC_GRP_COMMON}
    ${SRC_GRP_DATABASE}
	${SRC_GRP_DATASTORE}
    ${SRC_GRP_LOCKEDQ}
    ${SRC_GRP_LOG}
    ${SRC_GRP_THREAD}
    ${SRC_GRP_UTIL}
    revision_nr.h
    revision_sql.h
)

# OS specific files
if(WIN32)
  set(LIBRARY_SRCS
      ${LIBRARY_SRCS}
      ${SRC_GRP_WIN}
     )
else()
  set(LIBRARY_SRCS
      ${LIBRARY_SRCS}
      ${SRC_GRP_LINUX}
     )
endif()

include_directories(
  "${CMAKE_CURRENT_SOURCE_DIR}"
  ${CMAKE_CURRENT_SOURCE_DIR}/Utilities
  ${CMAKE_CURRENT_SOURCE_DIR}/Common
  ${CMAKE_CURRENT_SOURCE_DIR}/Log
  "${CMAKE_SOURCE_DIR}/dep"
  "${CMAKE_SOURCE_DIR}/src/framework"
  "${CMAKE_BINARY_DIR}"
  "${ACE_INCLUDE_DIR}"
  "${OPENSSL_INCLUDE_DIR}"
)

if(POSTGRESQL)
  include_directories("${PostgreSQL_INCLUDE_DIRS}")
else()
  include_directories("${MYSQL_INCLUDE_DIR}")
endif()

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/SystemConfig.h.in" "${CMAKE_CURRENT_BINARY_DIR}/SystemConfig.h")

add_library(${LIBRARY_NAME} STATIC
  ${LIBRARY_SRCS}
)

if(POSTGRESQL)
  target_link_libraries(${LIBRARY_NAME} ${PostgreSQL_LIBRARIES})
else()
  target_link_libraries(${LIBRARY_NAME} ${MYSQL_LIBRARY})
endif()

if(NOT ACE_USE_EXTERNAL)
  add_dependencies(${LIBRARY_NAME} ace)
endif()
